<?php

namespace App\Http\Controllers;

use App\loan_customer;
use Illuminate\Http\Request;
use Auth;

class ExamineController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $ids = [
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10,
        11,
    ];

//        loan_customer::whereNotIn('id', $ids)->delete();

//        dd(str_rands(18, true));

        //
        $basis =loan_customer::where('step', Auth::user()->auth) ->paginate(8);
        $view = [
          'basis' => $basis,
        ];
        return view('examine.index',$view);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
//        return view('examine.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
        $info =loan_customer::where('id',$id)->first();
        $view = [
            'info' => $info,
        ];
        return view('examine.detail',$view);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }

    public function handle($type, $id)
    {
        $arr = [
            'pass',
            'deny',
        ];

        if (!in_array($type, $arr) || !$id) {
            return back()->with('danger', '非法操作');
        }

        $info = loan_customer::find($id);

        if ($type == 'pass') {

            if ($info->money_type > $info->step) {
                $info->increment('step');
                return redirect()->route('examine.index')->with('success', '提交上级成功');
            }

            loan_customer::where('id',$id)->update(['status' => 1]);
            return redirect()->route('examine.index')->with('success', '审核通过');
        } else {
            loan_customer::where('id',$id)->update(['status' => 2]);

            return redirect()->route('examine.index')->with('danger', '审核不通过');
        }
    }
}
